<?php
$output = array();

if (!isset($_GET["id"])) {
    echo("No id specified");
    exit();
}
$id = $_GET["id"];

// import database connection variables and connectToMysql method
require_once __DIR__ . '/db_config.php';

$mysqli = connectToMysql();
$query = "SELECT company.id, company.name, company.description, company.profile, company.companyUrl, company.averageRating,
        location.latitude, location.longitude  FROM Company company left join Location location on company.location = location.id where company.id = " . $id;

if ($result = $mysqli->query($query)) {
    /* fetch object array */
    $row = $result->fetch_array();
    $output = array_map('utf8_encode', $row);

    $result->close();
}

/* close connection */
$mysqli->close();

$finalResult = json_encode($output, JSON_NUMERIC_CHECK);
$finalResult = str_replace('"latitude":""', '"latitude":null', $finalResult);
$finalResult = str_replace('"longitude":""', '"longitude":null', $finalResult);
$finalResult = str_replace('"averageRating":""', '"averageRating":null', $finalResult);

echo $finalResult;
?>